package com.scaffold.card.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import wangjg.commons.page.Page;

import com.scaffold.authority.dao.BasicBizDAO;
import com.scaffold.card.entity.Card;

@Repository
public class CardDAO extends BasicBizDAO<Card,Long>{

	public List<Card> pageQuery(Page page ) {
		DetachedCriteria criteria = DetachedCriteria.forClass(this.persistentClass);
		criteria.addOrder(Order.desc("id"));
		return this.findByCriteria(criteria, page);
	}

	public List<Card> pageQuery(Page page, Long categoryId, String keyword) {
		DetachedCriteria criteria = DetachedCriteria.forClass(this.persistentClass);
		if (categoryId != null) {
			criteria.add(Restrictions.eq("categoryId", categoryId));
		}
		if (keyword != null && !keyword.isEmpty()) {
			
		}
		criteria.addOrder(Order.desc("id"));
		return this.findByCriteria(criteria, page);
	}

}
